package pers.yurwisher.rubick.oauth2.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import pers.yurwisher.rubick.common.user.CurrentUser;
import pers.yurwisher.rubick.oauth2.security.OAuth2User;

/**
 * @author yq 2021/4/22 9:28
 * @description CustomUserDetailsService 自定义 UserDetailsService
 */
@Service
public class CustomUserDetailsService implements UserDetailsService {

    @Autowired
    private PasswordEncoder passwordEncoder;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        CurrentUser currentUser =  new CurrentUser();
        currentUser.setUsername(username);
        currentUser.setPassword(passwordEncoder.encode("123456"));
        currentUser.setEnabled(true);
        return new OAuth2User(currentUser);
    }
}
